<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>院感不良事件上报修改表</title>
  <link rel="stylesheet" href="../layui/css/layui.css">
  <script src="../layui/layui.js"></script>
  <style>
    td{
      padding-left: 10px;
      padding-bottom: 5px;
      padding-right: 20px;
      padding-top: 10px;
    }
  </style>
</head>
<body>
<button type="button" class="layui-btn"  id = “back” onclick="self.location = document.referrer;">返回</button>
<form class="layui-form" lay-filter="FormLoad">
  <table border="1px" width="100%" cellpadding="0">
    <tr >
      <td colspan="8" style="text-align: center; height: 50px"> <span style=" font-size: 20px">医院感染不良事件报告表</span> </td>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1" width="16.6%">
          报告时间：
        </td>
        <td colspan="2" width="33.2%">
          <input type="text" name="report_date" id="report_date" placeholder="" class="layui-input">
        </td>
        <td colspan="1" width="16.2%">
          报告科室：
        </td>
        <td colspan="2" width="33.2%">
          <input type="text" name="reporter_department" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <td rowspan="2" colspan="1">
        发生经过(发生时间，地点，事件内容，产生后果，采取的补偿措施与结果)：
      </td>
      <div class="layui-form-item">
        <td colspan="3" rowspan="2">
          <textarea name="bad_event_describe" style="height: 80px" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
        </td>
        <td colspan="1">
          签名
        </td>
        <td colspan="1" >
          <input type="text" name="reporter_sign" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1">
          日期
        </td>
        <td colspan="1" >
          <input type="text" name="reporter_sign_time" id="reporter_sign_time" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>

    <tr>
      <td rowspan="2" colspan="1">
        科内讨论分析（原因，教训，性质，处理意见）
      </td>
      <div class="layui-form-item">
        <td colspan="3" rowspan="2">
          <textarea name="department_analyse" style="height: 80px"  lay-verify="" placeholder="请输入" class="layui-textarea"></textarea>
        </td>
        <td colspan="1">
          签名
        </td>
        <td colspan="1" >
          <input type="text" name="department_analyse_sign" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1">
          日期
        </td>
        <td colspan="1" >
          <input type="text" name="department_analyse_sign_time" id="department_analyse_sign_time" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <td rowspan="2" colspan="1">
        院感科质量安全分析及处理意见：
      </td>
      <div class="layui-form-item">
        <td colspan="3" rowspan="2">
          <textarea name="infection_control_dept_analyse" style="height: 80px"  lay-verify="" placeholder="请输入" class="layui-textarea"></textarea>
        </td>
        <td colspan="1" width="8.3%">
          签名
        </td>
        <td colspan="1" width="24.9%">
          <input type="text" name="infection_control_dept_analyse_sign" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
    <tr>
      <div class="layui-form-item">
        <td colspan="1">
          日期
        </td>
        <td colspan="1" >
          <input type="text" name="infection_control_dept_analyse_sign_time" id="infection_control_dept_analyse_sign_time" placeholder="" class="layui-input">
        </td>
      </div>
    </tr>
  </table>
  <div class="layui-form-item">
    <div class="layui-input-block" style="text-align: center; margin-top: 50px">
      <button class="layui-btn" lay-submit lay-filter="save1">暂存</button>
      <button class="layui-btn" lay-submit lay-filter="save2">提交</button>
    </div>
  </div>
</form>

</body>

<script>

  let str;
  layui.use(['laydate','jquery','form','layedit','layer','table','laytpl'], function() {
    let $ = layui.jquery;
    let form = layui.form;
    let laydate = layui.laydate;
    var layer = layui.layer;
    var router = layui.router();
    laydate.render({
      elem: '#reporter_know_time' //指定元素
      , type: 'date'
    });
    laydate.render({
      elem: '#event_happen_time' //指定元素
      , type: 'date'
    });

    function getQueryVariable(variable)
    {
      let query = window.location.search.substring(1);
      let vars = query.split("&");
      for (let i=0;i<vars.length;i++) {
        let pair = vars[i].split("=");
        if(pair[0] == variable){return pair[1];}
      }
      return(false);
    }

    form.render();
    // 获取地址的中的值
    let form_code=getQueryVariable("form_code");
    console.log(form_code);
    $.ajax({
      url: '/look?form_code=' + form_code,
      type: 'get',
      success: function (data) {
        //console.log(data);
        let jsonObj = eval('(' + data + ')'); //获得jsonObj对象
        //console.log(jsonObj);
        //渲染 上报人和上报人单位
        let json = {};
        for(let i = 0; i<jsonObj.data.length; i++) {
          json[jsonObj.data[i].property_en_name] = jsonObj.data[i].detailed_data;
        }
        //console.log(json);
        form.val("FormLoad",json)
      }
    });

    form.on('submit(save1)', function (data) {
      layer.confirm('确定暂存吗？', {
        btn: ['确认', '取消'] //按钮
      }, function () {
        let json = {
          "form_code": form_code,
          "report_date":data.field.report_date,
          "reporter_department":data.field.reporter_department,
          "bad_event_describe":data.field.bad_event_describe,
          "reporter_sign":data.field.reporter_sign,
          "reporter_sign_time":data.field.reporter_sign_time,
          "department_analyse":data.field.department_analyse,
          "department_analyse_sign":data.field.department_analyse_sign,
          "department_analyse_sign_time":data.field.department_analyse_sign_time,
          "infection_control_dept_analyse":data.field.infection_control_dept_analyse,
          "infection_dept_analyse_sign":data.field.infection_control_dept_analyse_sign,
          "infection_dept_analyse_sign_time":data.field.infection_control_dept_analyse_sign_time,
          "status":1 //暂存
        };

        $.ajax({
          url: '/event/event_update',
          type: "POST",
          data: json,
          success: function (index) {
            layer.msg("修改成功");
            self.location = document.referrer;
          }
        })

      }, function () {
        self.location = document.referrer;
      });
      return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

    form.on('submit(save2)', function (data) {

      layer.confirm('确定提交吗？', {
        btn: ['确认', '取消'] //按钮
      }, function () {
        let json = {
          "form_code": form_code,
          "report_date":data.field.report_date,
          "reporter_department":data.field.reporter_department,
          "bad_event_describe":data.field.bad_event_describe,
          "reporter_sign":data.field.reporter_sign,
          "reporter_sign_time":data.field.reporter_sign_time,
          "department_analyse":data.field.department_analyse,
          "department_analyse_sign":data.field.department_analyse_sign,
          "department_analyse_sign_time":data.field.department_analyse_sign_time,
          "infection_control_dept_analyse":data.field.infection_control_dept_analyse,
          "infection_dept_analyse_sign":data.field.infection_control_dept_analyse_sign,
          "infection_dept_analyse_sign_time":data.field.infection_control_dept_analyse_sign_time,
          "status":2 //递交
        };
        console.log(json);
        console.log("123");

        $.ajax({
          url: '/event/event_update',
          type: "POST",
          data: json,
          success: function (index) {
            layer.msg("修改成功");
            self.location = document.referrer;
          }
        })

      }, function () {
      });
      return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

  })
</script>

</html>